/**
 * Created by hxpeng on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.pages.member')
        .controller('ChooseStudentCtrl', ChooseStudentCtrl);

    function ChooseStudentCtrl(AppUtils,MemberModel,$stateParams,$state,$scope) {
        var vm = this;
        vm.studentList = [];
        vm.noData = false;
        vm.nextState = $stateParams.nextState;

        var params = {};
        params.memberId = "11111";
        params.pageInfo = {};
        params.pageInfo.pageSize = 100;
        params.pageInfo.pageNumber = 1;
        MemberModel.getStudentList(params).$promise.then(function(response){
            if(response.stat == 'err'){
                AppUtils.showTipsTop("加载学生列表失败！");
            }else{
                var reponseDate = response.pageResult;
                var items = reponseDate.pageResult;
                if(items.length == 0){
                    vm.noData = true;
                }
                vm.studentList = _.clone(items);
            }
        })


        $(".entrust-create-screen").on("click",".card-facebook",function(e){
            $(this).find(".ion").toggleClass('ion-android-done');
        })

        $("#chooseAllStudentBtn").click(function(){
            if($(this).hasClass("ion-android-checkbox-outline")){
                $(this).removeClass("ion-android-checkbox-outline");
                $(this).addClass("ion-android-checkbox-outline-blank");
                $(".container").find(".ion").removeClass("ion-android-done");
            }else{
                $(this).addClass("ion-android-checkbox-outline");
                $(this).removeClass("ion-android-checkbox-outline-blank");
                $(".container").find(".ion").addClass("ion-android-done");
            }
        })

        $scope.next = function(){
            var studentArray = [];
            var resutArray = $(".container").find(".ion-android-done");
            if(resutArray.length < 1){
                AppUtils.showTipsTop("请选择学生留言！");
                return;
            }
            resutArray.each(function(){
                var studentId = $(this).attr("data-studentId");
                if(!AppUtils.isUndefinedOrNull(studentId)){
                    studentArray.push(studentId);
                }
            })
            $state.go(vm.nextState,{studentArray:studentArray});
        }


    }
})();